# Maintainer: Christian Rebischke <chris.rebischke@archlinux.org>

pkgname=kompose
pkgver=1.28.0
pkgrel=1
pkgdesc="Docker compose to Kubernetes transformation tool"
arch=('loong64' 'x86_64')
url="https://github.com/kubernetes/kompose"
license=('Apache')
makedepends=('go' 'git' 'jq') # git binary is needed for test scripts
depends=('glibc')
source=("${pkgname}-${pkgver}.tar.gz::https://github.com/kubernetes/kompose/archive/v${pkgver}.tar.gz")
sha512sums=('07ecff703d001b0ba7b64a341e2114764b89c4b64a31c5b9537e31d23759332b3e8fde6260e0007b6cd1555814fcdcc60df9de8433b7b2b9da8ad31762315f27')
options=('!lto')

prepare() {
  export GOPATH="${srcdir}"
  mkdir -p src/github.com/kubernetes "${GOPATH}/bin"
  mv "${pkgname}-${pkgver}" "src/github.com/kubernetes/${pkgname}"
  export PACKAGE_ROOT="${GOPATH}/src/github.com/kubernetes/${pkgname}"
}

build() {
  cd "${PACKAGE_ROOT}"
  export CGO_ENABLED=1
  export CGO_CPPFLAGS="${CPPFLAGS}"
  export CGO_CFLAGS="${CFLAGS}"
  export CGO_CXXFLAGS="${CXXFLAGS}"
  export CGO_LDFLAGS="${LDFLAGS}"
  export GOFLAGS="-buildmode=pie -trimpath -mod=readonly -modcacherw"
  go build -v .
  chmod +x ./kompose
}

# tests are failing right now due to a bug in script/cmd/cmd_test.go:28
#check() {
#  cd "${PACKAGE_ROOT}"
#  go test -v ./...
#}

package() {
  cd "${PACKAGE_ROOT}"
  install -Dsm755 ./kompose "${pkgdir}/usr/bin/kompose"
}
